package com.sdy.dcsb.web.controller.inboundservice;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sdy.common.model.BizException;
import com.sdy.common.model.Response;
import com.sdy.common.utils.Assert;
import com.sdy.mvc.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Snaky
 * @date 2020/4/14 16:11
 */
@Slf4j
@Controller
@RequestMapping("/DCSBWeb/test")
public class TestController extends BaseController {

    @GetMapping(value = "/get/getToken")
    @ResponseBody
    public Response getToken() throws Exception {
        String token = "4286d296838a465dade433fd5a651fa3";
        JSONObject json = new JSONObject();
        json.put("token",token);
        return Response.success(json);
    }

    @PostMapping(value = "/post/getPopBaseInfo")
    @ResponseBody
    public Response getPopBaseInfo(String token,String sfz) throws Exception {
        Assert.isBlank(token,"token不能为空");
        Assert.isBlank(sfz,"身份证为空");
        if(!"4286d296838a465dade433fd5a651fa3".equals(token)){
            throw new BizException("token非法");
        }

        JSONObject json = new JSONObject();
        if("410102198902030059".equals(sfz)){
            json.put("sfz",sfz);
            json.put("xm","张三");
            json.put("xb","男");
            json.put("mz","汉");
            json.put("gj","中国");
            json.put("hh","700662678");
            json.put("zz","郑州市郑上路105号院2号楼");
            json.put("hlrrq","2010-01-22 11:09:31.0");
        }

        return Response.success(json);
    }

    @PostMapping(value = "/post/getClfHtInfo")
    @ResponseBody
    public Response getClfHtInfo(HttpServletRequest request, String token,String htbh) throws Exception {
        Assert.isBlank(token,"token不能为空");
        Assert.isBlank(htbh,"合同编号不能为空");
        String appId = request.getHeader("gateway_appid");
        Assert.isBlank(appId,"appId不能为空");
        if(!"13a3557cd6b14823921842839699e316".equals(appId)){
            throw new BizException("appId不存在");
        }
        if(!"4286d296838a465dade433fd5a651fa3".equals(token)){
            throw new BizException("token非法");
        }


        if("2019100001".equals(htbh)){
            String result = "[{\"ContractNo\":\"2019100001\",\"HouseSourceNo\":\"25120\",\"IsRent\":\"\",\"TradeMoney\":\"100000\",\"IsLoan\":\"是\",\"LoanMoney\":\"\",\"LoanEnt\":\"\",\"SaveTime\":\"2019/1/8 9:42:48\"}]";
            JSONArray array = JSONArray.parseArray(result);
            return Response.success(array);
        }
        if("2019100004".equals(htbh)){
            String result = "[{\"ContractNo\":\"2019100004\",\"HouseSourceNo\":\"50528\",\"IsRent\":\"\",\"TradeMoney\":\"450000\",\"IsLoan\":\"否\",\"LoanMoney\":\"\",\"LoanEnt\":\"\",\"SaveTime\":\"2019/1/10 10:00:11\"},{\"ContractNo\":\"2019100004\",\"HouseSourceNo\":\"50707\",\"IsRent\":\"\",\"TradeMoney\":\"600000\",\"IsLoan\":\"是\",\"LoanMoney\":\"\",\"LoanEnt\":\"\",\"SaveTime\":\"2019/5/15 15:50:11\"}]";
            JSONArray array = JSONArray.parseArray(result);
            return Response.success(array);
        }
        return Response.success();
    }

    @PostMapping(value = "/post/getClfHouseInfo", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Response getClfHouseInfo(String token,@RequestBody JSONObject json) throws Exception {
        String houseSourceNo = json.getString("houseSourceNo");
        Assert.isBlank(token,"token不能为空");
        Assert.isBlank(houseSourceNo,"房源编号不能为空");
        if(!"4286d296838a465dade433fd5a651fa3".equals(token)){
            throw new BizException("token非法");
        }

        if("25120".equals(houseSourceNo)){
            String result = "[{\"HouseSourceNum\":\"25120\",\"RightCertType\":\"房屋所有权证号\",\"RightCertNum\":\"0901100247\",\"OwnerName\":\"刘英\",\"OwnerCertNum\":\"410105197605191627\",\"District\":\"金水区\",\"Road\":\"农业路\",\"SitNumGather\":\"金水区农业路28号4号楼东2单元5层21号\",\"UnitNum\":\"\",\"FloorNum\":\"5\",\"DoorNum\":\"\",\"ArchitArea\":\"177.18\",\"RoomArea\":\"164.07\",\"CountFloor\":\"6\",\"BuildDate\":\"2004\",\"HouseType\":\"四室二厅\",\"HouseUsage\":\"成套住宅\",\"ArchitStruct\":\"混合\",\"BalconyType\":\"\",\"SalePrice\":\"700000\",\"ZhuangXiu\":\"简单装修\"}]";
            JSONArray array = JSONArray.parseArray(result);
            return Response.success(array);
        }
        if("50528".equals(houseSourceNo)){
            String result = "[{\"HouseSourceNum\":\"50528\",\"RightCertType\":\"房屋所有权证号\",\"RightCertNum\":\"CC00000562\",\"OwnerName\":\"曹一零\",\"OwnerCertNum\":\"411717196604240873\",\"District\":\"中原区\",\"Road\":\"郑上路\",\"SitNumGather\":\"郑上路105号院2号楼3单元7号\",\"UnitNum\":\"\",\"FloorNum\":\"4\",\"DoorNum\":\"\",\"ArchitArea\":\"71.50\",\"RoomArea\":\"62.51\",\"CountFloor\":\"5\",\"BuildDate\":\"1987\",\"HouseType\":\"\",\"HouseUsage\":\"成套住宅\",\"ArchitStruct\":\"混合\",\"BalconyType\":\"\",\"SalePrice\":\"450000\",\"ZhuangXiu\":\"\"}]";
            JSONArray array = JSONArray.parseArray(result);
            return Response.success(array);
        }
        if("50707".equals(houseSourceNo)){
            String result = "[{\"HouseSourceNum\":\"50707\",\"RightCertType\":\"房屋所有权证号\",\"RightCertNum\":\"CC00091302\",\"OwnerName\":\"王三六\",\"OwnerCertNum\":\"622667190012223567\",\"District\":\"中原区\",\"Road\":\"支农路\",\"SitNumGather\":\"中原区支农路1号院9号楼3单元33号\",\"UnitNum\":\"\",\"FloorNum\":\"4\",\"DoorNum\":\"\",\"ArchitArea\":\"71.50\",\"RoomArea\":\"62.51\",\"CountFloor\":\"5\",\"BuildDate\":\"1987\",\"HouseType\":\"\",\"HouseUsage\":\"成套住宅\",\"ArchitStruct\":\"混合\",\"BalconyType\":\"\",\"SalePrice\":\"9999\",\"ZhuangXiu\":\"\"}]";
            JSONArray array = JSONArray.parseArray(result);
            return Response.success(array);
        }
        return Response.success();
    }
}
